import Vue from 'vue'
import VueRouters from 'vue-router'
import { MessageBox } from 'element-ui'
import Main from '../pages/Main/Main'
import Login from '../pages/Login/Login'
import Index from '../pages/Index/Index'

// 数据中心
import DataCenter from '@/pages/DataCenter/DataCenter'
import Maps from '@/pages/Map/Map'
//调度运输
import OrderManage from '../pages/OrderManage/OrderManage'
// import Maps from '../pages/DataCenterList/Maps'
import DispatchManage from '../pages/DispatchManage/DispatchManage'
import TransportationManage from '../pages/TransportationManage/TransportationManage'
import KuponoManage from '../pages/Kupono/KuponoManage'

//信息管理
import LedgerManage from '../pages/LedgerManage/LedgerManage'
import ContractManage from '../pages/ContractManage/ContractManage'
import ContractTemplate from '../pages/ContractManage/ContractTemplate'
import AnnualReport from '../pages/AnnualReport/AnnualReport'
import ArchivesManage from '../pages/ArchivesManage/ArchivesManage'

//报表管理
import Statement from '../pages/Statement/Statement'

// 基础数据
import EquipmentManage from '../pages/EquipmentManage/EquipmentManage'
import CarManage from '../pages/CarManage/CarManage'
import IncidenceRelation from '../pages/IncidenceRelation/IncidenceRelation'
import PoisonousWaste from '../pages/PoisonousWaste/PoisonousWaste'
import CompanyManage from '../pages/CompanyManage/CompanyManage'

import WasteRelation from '../pages//WasteRelation/WasteRelation.vue'
import OperationAndTransport from '../pages/OperationAndTransport/OperationAndTransport.vue'

//系统管理
import Message from '../pages/Message/Message'
import RolePermission from '../pages/RolePermission/RolePermission'
import MenuManage from '../pages/MenuManage/MenuManage'
import OperationLogs from '../pages/OperationLogs/operationLog'
import Users from '../pages/Users/Users'

Vue.use(VueRouters);

const routes = new VueRouters({
  routes: [{
      path: '/index',
      component: Main,
      name: '纽创固废智慧管理云平台',
      meta: {
        title: '纽创固废智慧管理云平台'
      },
      children: [{
          path: '/main/index',
          component: Index,
          name: '首页',
          meta: {
            title: '首页'
          }
        },
        {
          path: '/main/maps',
          component: Maps,
          name: '地图展示',
          meta: {
            title: '首页'
          }
        },
        {
          path: '/main/dataCenter',
          component: DataCenter,
          name: '数据列表',
          meta: {
            title: '数据列表'
          }
        },
        {
          path: '/main/orderManage',
          component: OrderManage,
          name: "订单管理",
          meta: {
            title: '订单管理'
          }
        },
        {
          path: '/main/dispatchManage',
          component: DispatchManage,
          name: "调度管理",
          meta: {
            title: '调度管理'
          }
        },
        {
          path: '/main/transportationManage',
          component: TransportationManage,
          name: "运输管理",
          meta: {
            title: '运输管理'
          }
        },
        {
          path: '/main/kuponoManage',
          component: KuponoManage,
          name: "联单管理",
          meta: {
            title: '联单管理'
          }
        },
        {
          path: '/main/ledgerManage',
          component: LedgerManage,
          name: "台账管理",
          meta: {
            title: '台账管理'
          }
        },
        {
          path: '/main/contractTemplate',
          component: ContractTemplate,
          name: "合同模板",
          meta: {
            title: '合同模板'
          }
        },
        {
          path: '/main/contractManage',
          component: ContractManage,
          name: "合同管理",
          meta: {
            title: '合同管理'
          }
        },
        {
          path: '/main/annualReport',
          component: AnnualReport,
          name: "年度申报",
          meta: {
            title: '年度申报'
          }
        },
        {
          path: '/main/archivesManage',
          component: ArchivesManage,
          name: "档案管理",
          meta: {
            title: '档案管理'
          }
        },
        {
          path: '/main/statement',
          component: Statement,
          name: "报表管理",
          meta: {
            title: '报表管理'
          }
        },

        {
          path: '/main/equipmentManage',
          component: EquipmentManage,
          name: "设备管理",
          meta: {
            title: '设备管理'
          }
        },
        {
          path: '/main/companyManage',
          component: CompanyManage,
          name: "单位管理",
          meta: {
            title: '单位管理'
          }
        },
        {
          path: '/main/carManage',
          component: CarManage,
          name: "车辆管理",
          meta: {
            title: '车辆管理'
          }
        },
        {
          path: '/main/incidenceRelation',
          component: IncidenceRelation,
          name: "关联关系管理",
          meta: {
            title: '关联关系管理'
          }
        },

        {
          path: '/main/poisonousWaste',
          component: PoisonousWaste,
          name: "危废种类管理",
          meta: {
            title: '危废种类管理'
          }
        },
        {
          path: '/main/message',
          component: Message,
          name: "消息管理",
          meta: {
            title: '消息管理'
          }
        },
        {
          path: '/main/rolePermission',
          component: RolePermission,
          name: "角色管理",
          meta: {
            title: '角色管理'
          }
        },
        {
          path: '/main/menuManage',
          component: MenuManage,
          name: "菜单管理",
          meta: {
            title: '菜单管理'
          }
        },
        {
          path: '/main/userManage',
          component: Users,
          name: '用户管理',
          meta: {
            title: '用户管理'
          }
        },

        {
          path: '/main/operationLog',
          component: OperationLogs,
          name: "操作日志",
          meta: {
            title: '操作日志'
          }
        },

        {
          path: '/main/wasteRelation',
          component: WasteRelation,
          name: "产废关联",
          meta: {
            title: '产废关联'
          }
        },
        {
          path: '/main/operationAndTransport',
          component: OperationAndTransport,
          name: "运营与运输关联",
          meta: {
            title: '运营与运输关联'
          }
        }
      ]
    },
    {
      path: '/',
      component: Login,
      name: '登录',
      meta: {
        title: "登录"
      }
    }

  ]
});

routes.beforeEach((to, from, next) => {
  if (to.meta.title) document.title = to.meta.title;
  let path = '';
  if (document.querySelector('.paths')) path = document.querySelector('.paths').innerText;
  // if (sessionStorage.nc_token) { // 判断是否登录
  //   next()
  // } else { // 没登录则跳转到登录界面
  //   next({
  //     path: '/'
  //   })
  // }

  if (from.path.includes('add') && from.query.id && !from.meta.isSave && path != '首页') {
    setTimeout(() => {
      MessageBox.confirm('内容未保存，是否退出？', '', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        next();
      }).catch(() => {});
    }, 200);
  } else {
    if (from.meta.isSave) from.meta.isSave = false;
    next();
  }
});
export default routes;
